//
//  YZProvinceController.m
//  天气预报
//
//  Created by jacoy on 16/5/4.
//  Copyright © 2016年 jacoy. All rights reserved.
//

#import "YZProvinceController.h"
#import "YZProvinces.h"
#import "YZCityController.h"
static NSString *provinceIdentifier = @"provinceIdentifier";
@interface YZProvinceController ()
@property (nonatomic,strong)NSArray *proArr;

@end

@implementation YZProvinceController
-(NSArray *)proArr{
    if (!_proArr) {
        _proArr=[YZProvinces provinces];
    }
    return _proArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title = @"请选择省份";
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.proArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:provinceIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:provinceIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    YZProvinces *province = self.proArr[indexPath.item];
    cell.textLabel.text = province.name;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YZCityController *cvc = [[YZCityController alloc]init];
    YZProvinces *province = self.proArr[indexPath.item];
    [self.navigationController pushViewController:cvc animated:YES];
    cvc.cities = province.cities;
}

@end
